package com.atguigu.gulimall.search.web;

import com.atguigu.gulimall.search.service.MallSearchService;
import com.atguigu.gulimall.search.vo.SearchParamVo;
import com.atguigu.gulimall.search.vo.SearchResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * 搜索页面
 *
 * @author LaiSanShan
 * @date 2021-08-11
 */
@Controller
public class SearchController {

    @Autowired
    MallSearchService mallSearchService;

    /**
     * 首页跳转搜索页面
     * 根据查询条件检索
     *
     * @param paramVo 查询条件
     * @return 搜索页面的所有信息
     */
    @GetMapping("/list.html")
    public String listPage(SearchParamVo paramVo, Model model, HttpServletRequest request) {
        paramVo.set_queryString(request.getQueryString());

        // 根据传来的查询参数，去es检索
        SearchResultVo result = mallSearchService.search(paramVo);
        model.addAttribute("result", result);

        return "list";
    }

}
